package com.qzsoft.system.modules.sysstation.service.impl;

import java.io.Serializable;
import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qzsoft.system.modules.sysstation.entity.SysStationAsphaltSensorEntity;
import com.qzsoft.system.modules.sysstation.mapper.SysStationAsphaltSensorMapper;
import com.qzsoft.system.modules.sysstation.service.SysStationAsphaltSensorService;
import com.qzsoft.system.modules.sysstation.service.SysStationService;

/**
 * @ClassName SysStationAsphaltSensorServiceImpl
 * @Description 沥青拌合楼传感器校正业务接口实现
 * @author linhuawei
 * @since 2021-11-25
 */
@Service
public class SysStationAsphaltSensorServiceImpl extends ServiceImpl<SysStationAsphaltSensorMapper, SysStationAsphaltSensorEntity>
        implements SysStationAsphaltSensorService {

    @Autowired
    private SysStationService sysStationService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdate(SysStationAsphaltSensorEntity entity) {
        // 更新传感器校正状态
        sysStationService.updateSensorConfig(entity.getId(), 1);

        // 判断数据是否存在
        SysStationAsphaltSensorEntity temp = baseMapper.selectById(entity.getId());

        // 判断添加、修改操作
        if (null == temp) {
            return save(entity);
        }
        return updateById(entity);
    }

    @Override
    public void deleteByStationId(Collection<? extends Serializable> stationIdList) {
        QueryWrapper<SysStationAsphaltSensorEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id", stationIdList);
        baseMapper.delete(queryWrapper);
    }

    @Override
    public void deleteByStationId(Serializable stationId) {
        QueryWrapper<SysStationAsphaltSensorEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", stationId);
        baseMapper.delete(queryWrapper);
    }

}
